package com.example.compreshensiveshop.service.imp;

import com.example.compreshensiveshop.dao.ProductImageDao;
import com.example.compreshensiveshop.po.ProductImagePO;
import com.example.compreshensiveshop.service.ProductImageService;
import com.example.compreshensiveshop.vo.ProductImagesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * ProductImage Service Implementation
 */
@Service
public class ProductImageServiceImpl implements ProductImageService {
    @Autowired
    private ProductImageDao productImageDao;
    @Override
    public List<ProductImagesVO> queryByPId(Long id) {
        List<ProductImagePO> productImagesVOS = productImageDao.queryByPId(id);
        List<ProductImagesVO> productImagesVOList = new ArrayList<>();
        for(ProductImagePO productImagePO : productImagesVOS){
            ProductImagesVO productImagesVO = ProductImagesVO.builder()
                    .id(productImagePO.getId())
                    .productId(productImagePO.getProductId())
                    .url(productImagePO.getUrl())
                    .build();
            productImagesVOList.add(productImagesVO);
        }
        return productImagesVOList;
    }

    @Override
    public void addProductImages(List<ProductImagePO> productImagePOs) {
        productImageDao.addProductImages(productImagePOs);
    }

    @Override
    public void updateProductImages(ProductImagePO productImagePO) {
        productImageDao.updateProductImages(productImagePO);
    }

    @Override
    public void deleteImages(Long id) {
        productImageDao.deleteImages(id);
    }
}